import express from 'express';
import uploadCrud from '../controller/upload';
import multer from 'multer';
import path from 'path';

const router = express.Router();

const uploadVideo = multer({ dest: path.join(__dirname, '../static/temporary/'), limits: { fieldSize: 1024 * 1024 * 5 } });

export = (app: any) => {
  router.post('/upload', uploadVideo.single('file'), uploadCrud.upload); // token上传文件
  router.get('/download/:file/:name', uploadCrud.download); // 下载文件
  router.get('/find', uploadCrud.find); // 查找文件列表
  router.delete('/del', uploadCrud.del); // 删除文件
  router.post('/img', uploadCrud.img);
  router.post('/video', uploadVideo.single('file'), uploadCrud.video); // 分片上传视频

  app.use('/node/api/file', router);
};
